package Exercise.LambdaAndArrays;


import java.util.Arrays;

public class Sort {
    public static void main(String[] args) {
        FriendsInfor friend1 = new FriendsInfor("Jack", 18, 1.85);
        FriendsInfor friend2 = new FriendsInfor("Nick", 20, 1.75);
        FriendsInfor friend3 = new FriendsInfor("Black", 18, 2.01);
        FriendsInfor friend4 = new FriendsInfor("Alic", 18, 1.85);
        FriendsInfor[] infors = new FriendsInfor[]{friend1, friend2, friend3, friend4};
//        非lambda表达式
//        Arrays.sort(infors, new Comparator<FriendsInfor>() {
//            @Override
//            public int compare(FriendsInfor o1, FriendsInfor o2) {
//                double temp = o1.getAge() - o2.getAge();
//                temp = temp == 0 ? o1.getHeight() - o2.getHeight() : temp;
//                temp = temp == 0 ? o1.getName().compareTo(o2.getName()) : temp;
//                if(temp == 0){
//                    return 0;
//                } else if(temp > 0){
//                    return 1;
//                } else {
//                    return -1;
//                }
//            }
//        });
//      lambda表达式
        Arrays.sort(infors, (o1, o2) -> {
            double temp = o1.getAge() - o2.getAge();
            temp = temp == 0 ? o1.getHeight() - o2.getHeight() : temp;
            temp = temp == 0 ? o1.getName().compareTo(o2.getName()) : temp;
            if(temp == 0){
                return 0;
            } else if(temp > 0){
                return 1;
            } else {
                return -1;
            }
        });
        for (FriendsInfor friend : infors) {
            System.out.println(friend);
        }
    }
}
